package com.myteam.fugaocrm.sqldb.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.myteam.fugaocrm.modle.FgRemindMessage;

/**
 * 用户Mapper
 * @author BZX
 */
public interface FgRemindMessageMapper {

	
	// ==================== 通用 ====================

	/** 按照类别进行删除 */
	@Select("DELETE FROM fg_remind_message WHERE type_id = #{typeId}")
	public void deleteRemindByTypeId(@Param("typeId") Integer typeId);

	/** 按照类别进行查询 */
	@Select("SELECT * FROM fg_remind_message WHERE type_id = #{typeId}")
	public List<FgRemindMessage> selectRemindByTypeId(@Param("typeId") Integer typeId);
	
	// ==================== 其他 ====================
	
	/** 查询提醒数量(当前用户的提醒数量) */
	@Select(
		"SELECT COUNT(remind.remind_message_id) " + 
		"FROM fg_remind_message remind " + 
		"LEFT JOIN fg_project project ON project.project_id = remind.project_id " + 
		"WHERE project.staff_id = #{staffId} "
	)
	public Integer selectRemindCount(@Param("staffId") Integer staffId);
	
	/** 查询提醒数据(当前用户的提醒数据) */
	@Select(
		"SELECT remind.* " + 
		"FROM fg_remind_message remind " + 
		"LEFT JOIN fg_project project ON project.project_id = remind.project_id " + 
		"WHERE project.staff_id = #{staffId} "
	)
	public List<FgRemindMessage> selectRemindList(@Param("staffId") Integer staffId);
	
	// ==================== 售前日志 ====================
	
	/** 查询全部售前日志 */
	@Select("SELECT * FROM fg_remind_message WHERE log_id IS NOT NULL AND is_delete = 0")
	public List<FgRemindMessage> selectAllLog();
	
	/** 删除售前日志 */
	@Select("DELETE FROM fg_remind_message WHERE log_id = #{logId}")
	public void deleteLog(@Param("logId") Integer logId);
	
	/** 新增售前日志 */
	@Insert("INSERT into fg_remind_message(type_id, log_id,project_id,remind_content) VALUES(#{typeId}, #{logId},#{projectId},#{remindContent})")
	public void insertLog(Map<String, Object> param);
	
	// ==================== 合作商付款 ====================
	
	/** 删除合作商付款 */
	@Select("DELETE FROM fg_remind_message WHERE partner_detail_id = #{partnerDetailId}")
	public void deletePartnerDetail(@Param("partnerDetailId") Integer partnerDetailId);

	/** 新增合作商付款 */
	@Insert("INSERT into fg_remind_message(type_id, partner_detail_id,project_id,remind_content) VALUES(#{typeId}, #{partnerDetailId},#{projectId},#{remindContent})")
	public void insertPartnerDetail(Map<String, Object> param);

	// ==================== 合同明细 ====================
	
	/** 删除待开票合同明细 */
	@Select("DELETE FROM fg_remind_message WHERE contract_detail_id = #{contractDetailId} AND is_billing = 'N'")
	public void deleteBillContractDetail(@Param("contractDetailId") Integer contractDetailId);
	
	/** 删除待支付合同明细 */
	@Select("DELETE FROM fg_remind_message WHERE contract_detail_id = #{contractDetailId} AND is_payment = 'N'")
	public void deletePayContractDetail(@Param("contractDetailId") Integer contractDetailId);
	
	/** 新增合同明细待开票记录 */
	@Insert("INSERT into fg_remind_message(type_id, contract_detail_id, project_id, remind_content, is_billing) VALUES (#{typeId}, #{contractDetailId}, #{projectId}, #{remindContent}, #{isBilling})")
	public void insertContractDetailBill(Map<String, Object> param);
	
	/** 新增合同明细待支付记录 */
	@Insert("INSERT into fg_remind_message(type_id, contract_detail_id, project_id, remind_content, is_payment) VALUES(#{typeId}, #{contractDetailId}, #{projectId}, #{remindContent}, #{isPayment})")
	public void insertContractDetailPay(Map<String, Object> param);
	
	// ==================== 巡检记录 ====================
	
	/** 删除待巡检记录 */
	@Select("DELETE FROM fg_remind_message WHERE patrol_id = #{patrolId}")
	public void deleteProjectPafrolRecord(@Param("patrolId") Integer patrolId);
	
	/** 新增合同明细待支付记录 */
	@Insert("INSERT into fg_remind_message(type_id, patrol_id,project_id,remind_content) VALUES(#{typeId}, #{patrolId},#{projectId},#{remindContent})")
	public void insertProjectPafrolRecord(Map<String, Object> param);
	
	// ==================== 售前超过签约时间提醒 ====================
	
	/** 新增售前超过签约时间提醒 */
	@Insert("INSERT into fg_remind_message(type_id, project_id, remind_content) VALUES(#{typeId}, #{projectId}, #{remindContent})")
	public void insertSign(Map<String, Object> param);
}
